IF
ELSE
THEN

Syntax: IF condition ....
Location: QL ROM

This command is used to mark the start of yet another powerful SuperBASIC structure which allows a program to perform various functions dependent upon the status of a  condition. The condition will always be interpreted as having either the value 1 (true) or 0 (false), using boolean logic if necessary. Such conditions may be simple, such as x=2 or complex, as in x=3 AND (y=1 OR y=2).

There are actually two forms of the SuperBASIC structure:

IF condition [THEN | :] statement {:statement} [:ELSE statement {:statement}]
, or

IF condition [{THEN | :}]
{:statement}
...    
[ELSE]
{:statement}
...
END IF

The first syntax represents in-line code, and the keyword THEN can either appear or be replaced by a colon (:). If the condition is true, the statements followiare all the same:   

IF x=1 : PRINT 'x is 1'   
IF x=1 THEN PRINT 'x is 1'   
IF x=1 THEN:PRINT 'x is 1'

If during processing of the statements following THEN, a corresponding ELSE keyword is found, the interpreter will search the line for the corresponding END IF, in which case control will jump to the statement following the END IF. If however, the line does not contain a corresponding END IF, as with all other types on in-line code, control will jump to the next program line.

On the other hand, if the condition is false, the interpreter will search the line for the corresponding ELSE, which, if found, will force control to jump to the first statement following ELSE. Control then just continues along the program line and to the next program line. 

Note that a colon must appear before the word ELSE, and although not strictly necessary after the word ELSE, it is advisable to place a colon after the ELSE keyword (see the Note below). If ELSE does not appear, control is passed to the statement following the corresponding END IF, or if not present, the next program line.

The second syntax represents the much more flexible long-form of the IF..END IF statement. On the first line containing the IF condition, the keyword THEN may be replaced by a colon, or even omitted altogether. If the condition is true, control is passed to the next program line. If during interpretation, an ELSE statement is found, the interpreter searches for the corresponding END IF and passes control to the statement following this.

If the condition is false, the interpreter once again searches for a corresponding ELSE. If this is not present, then control is passed to the next statement after the corresponding END IF. If on the other hand, ELSE is present, control passes to the statement following ELSE (which may be on the same line as the ELSE keyword). There is no need to follow ELSE by a colon in this long form.

CROSS-REFERENCE:
SELect ON provides a much quicker (although less flexible) means of testing a variable. 
Other SuperBASIC structures are WHEN var, WHEN ERRor, DEFine PROCedure,  DEFine FuNction,  REPeat and FOR.
